import type {
  MealCenterItem,
  AddressItem,
  AddressParams,
  PeisongItem,
  SelectMealItem,
  PeiSongDian,
} from '@/types/address'
import type { CategoryTopItem } from '@/types/category'
import { http } from '@/utils/http'

/**
 * 添加收货地址
 * @param data 请求参数
 */
export const postMemberAddressAPI = (data: AddressParams) => {
  return http({
    method: 'POST',
    url: '/member/address',
    data,
  })
}
/**
 * 添加出餐中心
 * @param data 请求参数
 */
export const postMealAddressAPI = (data: MealCenterItem) => {
  return http({
    method: 'POST',
    url: '/system/mealcenter',
    data,
  })
}
//新建配送点
export const postPeisongAddressAPI = (data: PeisongItem) => {
  return http({
    method: 'POST',
    url: '/system/peisongdian',
    data,
  })
}
/**
 * 获取出餐门店中心列表
 */
export const getMealAddressAPI = () => {
  return http<MealCenterItem[]>({
    method: 'GET',
    url: '/system/mealcenter',
  })
}

/**
 * 获取出餐门店中心列表
 */
export const selectMealAddressAPI = () => {
  return http<SelectMealItem[]>({
    method: 'GET',
    url: '/system/selectmealcenter',
  })
}

/**
 * 获取配送点列表
 */
export const getPeisongAddressAPI = (latitude?: number, longitude?: number) => {
  return http<PeisongItem[]>({
    method: 'GET',
    url: '/system/peisongdian',
    data: { latitude, longitude },
  })
}

/**
 * 获取收货地址列表
 */
export const getMemberAddressAPI = () => {
  return http<AddressItem[]>({
    method: 'GET',
    url: '/member/address',
  })
}
/**
 * 获取收货地址详情
 * @param id 地址id(路径参数)
 */
export const getMemberAddressByIdAPI = (id: string) => {
  return http<AddressItem>({
    method: 'GET',
    url: `/system/mealcenter/${id}`,
  })
}
/**
 * 获取出餐中心详情
 * @param id 地址id(路径参数)
 */
export const getMealAddressByIdAPI = (id: string) => {
  return http<MealCenterItem[]>({
    method: 'GET',
    url: `/system/mealcenter`,
    data: { id },
  })
}

/**
 * 获取配送点列表
 * @param id 地址id(路径参数)
 */
export const getPeisongAddressByIdAPI = (id: number) => {
  return http<PeisongItem[]>({
    method: 'GET',
    url: `/system/peisongdian`,
    data: { id },
  })
}
/**
 * 修改收货地址
 * @param id 地址id(路径参数)
 * @param data 表单数据(请求体参数)
 */
export const putMemberAddressByIdAPI = (id: string, data: AddressParams) => {
  return http({
    method: 'PUT',
    url: `/system/mealcenter/${id}`,
    data,
  })
}
/**
 * 修改出餐中心
 * @param id 地址id(路径参数)
 * @param data 表单数据(请求体参数)
 */
export const putMealAddressByIdAPI = (data: MealCenterItem) => {
  return http({
    method: 'PUT',
    url: `/system/mealcenter`,
    data,
  })
}

/**
 * 修改配送点
 * @param id 地址id(路径参数)
 * @param data 表单数据(请求体参数)
 */
export const putPeisongAddressByIdAPI = (data: PeisongItem) => {
  return http({
    method: 'PUT',
    url: `/system/peisongdian`,
    data,
  })
}
/**
 * 删除出餐中心
 * @param id 地址id(路径参数)
 */
export const deleteMealAddressByIdAPI = (id: string) => {
  return http({
    method: 'DELETE',
    url: `/system/mealcenter`,
    data: { id },
  })
}
/**
 * 删除配送点
 * @param id 地址id(路径参数)
 */
export const deletePeisongAddressByIdAPI = (id: number) => {
  return http({
    method: 'DELETE',
    url: `/system/peisongdian`,
    data: { id },
  })
}
/**
 * 删除收货地址
 * @param id 地址id(路径参数)
 */
export const deleteMemberAddressByIdAPI = (id: string) => {
  return http({
    method: 'DELETE',
    url: `/member/address/${id}`,
  })
}

/**
 * 获取截单时间
 * @param id 地址id(路径参数)
 */
export const getJieDanByIdAPI = (type: string) => {
  return http<CategoryTopItem[]>({
    method: 'GET',
    url: `/system/deadline`,
    data: { type },
  })
}

/**
 * 修改截单时间
 * @param id 地址id(路径参数)
 * @param data 表单数据(请求体参数)
 */
export const putJieDanByTypeAPI = (data: CategoryTopItem) => {
  return http({
    method: 'PUT',
    url: `/system/deadline`,
    data,
  })
}
